#!/usr/bin/env python

import gtk
from mxit import encryption
from mxit import errors
import gettext
gettext.install('blendIT','locale');

class signals:
   def __init__(self,blend):
      self.blend = blend;
      
   def on_response(self,widget,response,entry,check,conv,eMID):
      if response == gtk.RESPONSE_ACCEPT:
         if entry.get_text() != None or entry.get_text() != "":
            message = conv.awaitingEncryptedMessages[eMID];
            try:
               msg = encryption.decrypt_message(message.message,entry.get_text());
               message.message = msg;
               self.blend.gui.chatWindow.parseMessage(message,conv);
               if check.get_active() == True:
                  conv.receiveEncryptKey = entry.get_text();

               conv.awaitingEncryptedMessages.pop(eMID);
               widget.destroy();
            except errors.MxitException:
               # Add in error message here.
               self.blend.gui.createErrorMessage(widget,_("The password you entered was incorrect."));
               widget.run();
         else:
            widget.destroy();
      else:
         widget.destroy();